<?php
error_reporting(0);
$err = isset($_GET['error']) ? $_GET['error'] : null ;

require'../clases/sesiones.php';
$objses = new Sesion();
$objses->iniciar();

$user = isset($_SESSION['user']) ? $_SESSION['user'] : null ;
$profile = $_SESSION['idprofile'];
$habilitado = $_SESSION['habilitado'];
if($user == ''){
    header('Location: ../index.php?error=2');
}elseif($habilitado == false){
	header('Location: ../index.php?error=5');
}
?>
<?php 
    require'../clases/cargos.php';
    require'../clases/config.php';
    require'../clases/usuarios.php';
    require'../clases/acciones.php';
?>
<!DOCTYPE html>
<html lang = "es">
    <head>
        <title>Ingresar Cargos</title>
        <meta charset = "utf-8" />
        <link rel="stylesheet" type="text/css" href="../css/intranet.css">
        <link rel="stylesheet" type="text/css" href="css/forms.css">
        <script src="../js/jquery.min.js"></script>
        <script src = "../js/mis-contactos.js"></script>
    </head>
    <body>
        <header id="header">
            <hgroup>
                <h1 class="site_title"><a href="index.html">Intranet Renacer</a></h1>
            </hgroup>
        </header>
        <section id="secondary_bar">
            <div class="user">
                <p><?php echo $_SESSION['name'] . " " . $_SESSION['apep'];?> (<a style="text-decoration: underline; color: blue;" href="log_out.php">Salir</a>)</p>
                <!-- <a class="logout_user" href="#" title="Logout">Logout</a> -->
            </div>
            </section>
            <aside id="sidebar">
                <?php
                    $objUsuario = new Usuario();
                    $con = new Coneccion();
                    $bd = $con->conectar_bd();
                    $objUsuario->smenu();
                    $con->desconectar_bd($bd);
                ?>
            </aside>
            <section id="main" class="column">
                <article class="module width_full">
                <?php
                    if(isset($_POST['submit'])){
                        if($_POST['nombre'] == ''){
                                    $errors = '<span class="error">Ingrese su nombre</span>';
                                }else if($_POST['descr'] == ''){
                                    $errors = '<span class="error">Ingrese un asunto</span>';
                                }else{
                                    $con = new Coneccion();
                                    $bd = $con->conectar_bd();
                                    $cargo = new Cargo();
                                    $agregar_cargo = $cargo->insertar_cargo();
                                    echo '<h4 class="alert_success">Cargo ingresado correctamente</h4>';
                                    $con->desconectar_bd($bd);
                                    header('Refresh: 2; Url= Ingresar_cargos.php');


                        }   
                    }
                ?>
                    <form id="agregar_cargo" class="contact_form" name="nuevocargo" action="" method="post">
                        <ul>
                            <li>
                                <label for="name">Nombre:</label>
                                <input type="text" name="nombre" maxlength="30" pattern="[0-9a-zA-Z].{1,30}" title="Largo minimo requerido es de 2 y maximo 30" required />
                                <span class="form_hint">Debe ingresar un nombre, maximo 30 caracteres, minimo 2</span>
                            </li>
                            <li>
                                <label for="name">Descripcion:</label>
                                <textarea name="descr" pattern="[0-9a-zA-Z].{1,255}" required /></textarea>
                                <span class="form_hint">Debe ingresar una descripcion</span>
                            </li>
                            <li>
                                <button class="submit" name="submit" type="submit">Agregar cargo</button>
                            </li>
                        </ul>
                    </form>
                                    <script type="text/javascript">
                        // Change the selector if needed
                    var $table = $('table.scroll'),
                        $bodyCells = $table.find('tbody tr:first').children(),
                        colWidth;

                    // Adjust the width of thead cells when window resizes
                    $(window).resize(function() {
                        // Get the tbody columns width array
                        colWidth = $bodyCells.map(function() {
                            return $(this).width();
                        }).get();
                        
                        // Set the width of thead columns
                        $table.find('thead tr').children().each(function(i, v) {
                            $(v).width(colWidth[i]);
                        });    
                    }).resize(); // Trigger resize handler
                    </script>
            </article>
        </section>
    </body>
</html>